from wcs.libs.items import items
from wcs.libs.players import players

cheaperItem = items.addItem("Cloak Of Shadows I")
cheaperItem.setGroup("enhancement")
cheaperItem.setCost(2000)
cheaperItem.setDescription("Become 75% Visible")
cheaperItem.setMaxCount(1)
cheaperItem.aliveToUse = True

expensiveItem = items.addItem("Cloak Of Shadows II")
expensiveItem.setGroup("enhancement")
expensiveItem.setCost(3500)
expensiveItem.setDescription("Become 50% Visible")
expensiveItem.setMaxCount(1)
expensiveItem.aliveToUse = True

def wcs_item_bought(event_var):
    """
    Executed when an item is bought. Assign the alpha accordingly if the item
    bought was in deed one of the Clock of Shaddows.
    """
    userid = event_var['userid']
    player = players[userid]
    if event_var['item'] == 'Cloak Of Shadows I':
        player.fade(int(player["alpha"] * 0.75), 5)
    elif event_var['item'] == 'Cloak Of Shadows II':
        player.fade(int(player["alpha"] * 0.5), 5)

def player_spawn(event_var):
    """
    Executed when a player spawns. Assign the alpha accordingly if they have
    bought a cloak of shadows whilst dead.
    """
    userid = event_var['userid']
    player = players[userid]
    if player.getItem("Cloak Of Shadows I").count:
        player.fade(int(player["alpha"] * 0.75), 5)
    elif player.getItem("Cloak Of Shadows II").count:
        player.fade(int(player["alpha"] * 0.5), 5)